using System;
using NUnit.Framework;
using ValidationFramework.Reflection;
using ValidationFramework.Tests.Performance.TestHelpers;

namespace ValidationFramework.Tests.Performance
{
	[TestFixture]
	[Ignore]
	public class PerformanceTest
	{
		public class ClassToValidate
		{

			[AlwaysFail]
			public int PropertyToValidate
			{
				get;
				set;
			}
			[AlwaysPass]
			public int PropertyToValidate2
			{
				get;
				set;
			}

			public int TestMethod([AlwaysFail] int param1)
			{
				return 0;
			}
		}

		readonly RuntimeTypeHandle classToValidateHadle = typeof(ClassToValidate).TypeHandle;
		readonly RuntimeMethodHandle methodToValidateHadle = typeof(ClassToValidate).GetMethod("TestMethod").MethodHandle;

        [Test]
        public void ValidateValidPropertyUsingString()
        {
			Validation.Initialize();

            const int iterations = 1000000;

            const string memberName = "PropertyToValidate";
            var classToValidate = new ClassToValidate { PropertyToValidate = 10 };
            var propertyValidationManager = Validation.GetPropertyValidationManager(classToValidate);
            using (var disposableStopwatch = new DisposableStopwatch("Validate Valid Property using string", iterations))
            {
                disposableStopwatch.Run(() => propertyValidationManager.Validate(memberName));
            }
        }

        [Test]
        public void ValidateInvalidPropertyUsingString()
        {
			Validation.Initialize();

            const int iterations = 1000;
            const string memberName = "PropertyToValidate2";
            var classToValidate = new ClassToValidate();
			var propertyValidationManager = Validation.GetPropertyValidationManager(classToValidate);
            propertyValidationManager.Validate(memberName);
            using (var disposableStopwatch = new DisposableStopwatch("Validate Invalid Property using string", iterations))
            {
                disposableStopwatch.Run(() => propertyValidationManager.Validate(memberName));
            }
        }
	}
}
